﻿namespace IPMS.BLL
{
    using IPMS.DAL;
    using System;
    using System.Data;
    using System.Data.SqlClient;

    public class DocumentType
    {
        private string _Folder;
        private string _Section;
        private string _Type;
        private string _TypeSeq;

        public DocumentType(string section, string type, string folder)
        {
            this._Section = section;
            this._Type = type;
            this._Folder = folder;
        }

        public string GetDocumentTypeFolder(string section, string type)
        {
            SqlCommand sqlCmd = new SqlCommand();
            DataAccessLayer DAL = new DataAccessLayer();
            DAL.AddParamToSQLCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@Section", SqlDbType.NVarChar, 0xff, ParameterDirection.Input, section.ToString());
            DAL.AddParamToSQLCmd(sqlCmd, "@Type", SqlDbType.NVarChar, 0xff, ParameterDirection.Input, type.ToString());
            DAL.AddParamToSQLCmd(sqlCmd, "@Folder", SqlDbType.NVarChar, 0xff, ParameterDirection.Output, null);
            DAL.SetCommandType(sqlCmd, CommandType.StoredProcedure, "GetDocumentTypeFolderSp");
            DAL.ExecuteScalarCmd(sqlCmd);
            int resultValue = (int) sqlCmd.Parameters["@ReturnValue"].Value;
            try
            {
                return (string) sqlCmd.Parameters["@Folder"].Value;
            }
            catch (Exception)
            {
                return null;
            }
        }

        public int GetDocumentTypeInfo(string section, string type)
        {
            SqlCommand sqlCmd = new SqlCommand();
            DataAccessLayer DAL = new DataAccessLayer();
            DAL.AddParamToSQLCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@Section", SqlDbType.NVarChar, 100, ParameterDirection.Input, section.ToString());
            DAL.AddParamToSQLCmd(sqlCmd, "@TypeSeq", SqlDbType.NVarChar, 30, ParameterDirection.Input, type.ToString());
            DAL.AddParamToSQLCmd(sqlCmd, "@Type", SqlDbType.NVarChar, 100, ParameterDirection.Output, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@Folder", SqlDbType.NVarChar, 100, ParameterDirection.Output, null);
            DAL.SetCommandType(sqlCmd, CommandType.StoredProcedure, "RetrieveDocumentTypeSp");
            DAL.ExecuteScalarCmd(sqlCmd);
            int resultValue = (int) sqlCmd.Parameters["@ReturnValue"].Value;
            this._Type = (string) sqlCmd.Parameters["@Type"].Value;
            this._Folder = (string) sqlCmd.Parameters["@Folder"].Value;
            return resultValue;
        }

        public string GetPathDocumentServer()
        {
            SqlCommand sqlCmd = new SqlCommand();
            DataAccessLayer DAL = new DataAccessLayer();
            DAL.AddParamToSQLCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            DAL.AddParamToSQLCmd(sqlCmd, "@ServerDocPath", SqlDbType.NVarChar, 0xff, ParameterDirection.Output, null);
            DAL.SetCommandType(sqlCmd, CommandType.StoredProcedure, "GetPathDocumentServerSp");
            DAL.ExecuteScalarCmd(sqlCmd);
            int resultValue = (int) sqlCmd.Parameters["@ReturnValue"].Value;
            try
            {
                return (string) sqlCmd.Parameters["@ServerDocPath"].Value;
            }
            catch (Exception)
            {
                return null;
            }
        }

        public string folder
        {
            get
            {
                return this._Folder;
            }
            set
            {
                this._Folder = value;
            }
        }

        public string section
        {
            get
            {
                return this._Section;
            }
            set
            {
                this._Section = value;
            }
        }

        public string type
        {
            get
            {
                return this._Type;
            }
            set
            {
                this._Type = value;
            }
        }

        public string TypeSeq
        {
            get
            {
                return this._TypeSeq;
            }
        }
    }
}

